package com.example.springboot.mapper;

import com.example.springboot.entity.Device;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeviceMapper {
    @Select("SELECT * from sys_device")
    List<Device> findAll();

    @Insert("insert into sys_device(device_name,device_number,device_size,device_type,status,brand,utility,situation,supplier_id,buyer_name,buy_date,durability,price) " +
            "VALUES (#{deviceName},#{deviceNumber},#{deviceSize},#{deviceType},#{status},#{brand},#{utility},#{situation},#{supplierId},#{buyerName},#{buyDate},#{durability},#{price});")
    int insert(Device device);

    int update(Device device);

    @Update("update sys_device set status = '审核中' where device_number = #{deviceNumber}")
    int updateStatus(String deviceNumber);


    @Update("update sys_device set status = #{status}, situation = #{situation} where device_number = #{deviceNumber}")
    int  updateOutstore(String deviceNumber,String status,String situation);

    @Delete("delete from sys_device where id = #{id}")
    Integer deleteById(@Param("id")Integer id);

    @Select("select id from sys_device where device_number = #{deviceNumber}")
    Integer selectByNumber(String deviceNumber);

    @Select("select device_number from sys_device where id = #{id}")
    String selectById(Integer id);

    @Select("select * from sys_device where device_number like concat('%',#{deviceNumber},'%') limit #{pageNum},#{pageSize}")
    List<Device> selectPage(Integer pageNum, Integer pageSize, String deviceNumber);

    @Select("select count(*) from sys_device where device_number like concat('%',#{deviceNumber},'%')")
    Integer selectTotal(String deviceNumber);

    @Select("select * from sys_device where status like concat('%',#{status},'%') limit #{pageNum},#{pageSize}")
    List<Device> selectStatus(Integer pageNum, Integer pageSize, String status);

    @Select("select count(*) from sys_device where status like concat('%',#{status},'%')")
    Integer selectTotalStatus(String status);
}
